import RequestUtils from '@/utils/RequestUtils'

const groupName = 'activiti'
const apiName = 'process'

export default {
  add(params = {}) {
    return RequestUtils({
      url: `/${groupName}/${apiName}`,
      method: 'POST',
      data: {
        ...params
      }
    })
  },
  remove(id) {
    return RequestUtils({
      url: `/${groupName}/${apiName}/${id}`,
      method: 'DELETE'
    })
  },
  edit(params = {}) {
    return RequestUtils({
      url: `/${groupName}/${apiName}`,
      method: 'PUT',
      data: {
        ...params
      }
    })
  },
  /**
   * 激活流程
   * @param id
   * @returns {AxiosPromise}
   */
  active(id) {
    return RequestUtils({
      url: `/${groupName}/${apiName}/active/${id}`,
      method: 'PUT'
    })
  },
  /**
   * 挂起流程
   * @param id
   * @returns {AxiosPromise}
   */
  suspend(id) {
    return RequestUtils({
      url: `/${groupName}/${apiName}/suspend/${id}`,
      method: 'PUT'
    })
  },
  /**
   * 将部署的流程转换为模型
   * @param id
   * @returns {AxiosPromise}
   */
  convertToModel(id) {
    return RequestUtils({
      url: `/${groupName}/${apiName}/convertToModel/${id}`,
      method: 'POST'
    })
  },
  get(id) {
    return RequestUtils({
      url: `/${groupName}/${apiName}/${id}`,
      method: 'GET'
    })
  },
  list(params = {}) {
    return RequestUtils({
      url: `/${groupName}/${apiName}/search`,
      method: 'POST',
      data: {
        ...params
      }
    })
  },
  page(params = {}, page) {
    return RequestUtils({
      url: `/${groupName}/${apiName}/search/${page.current}/${page.pageSize}`,
      method: 'POST',
      data: {
        ...params
      }
    })
  },
  downloadResource(params = {}) {
    return RequestUtils({
      url: `/${groupName}/${apiName}/downloadResource`,
      method: 'POST',
      data: {
        ...params
      }
    })
  },
  image(deploymentId) {
    return RequestUtils({
      url: `/${groupName}/${apiName}/image/${deploymentId}`,
      method: 'POST'
    })
  }
}
